<template>
  <h6>appDome</h6>
  <h6>{{ firstName }}</h6>
  <!-- 两者搭配使用 v-model @update:modelValue -->
  <input type="text" v-model="firstName" @update:modelValue="onFirstName" />

  <hr />
  <!-- 升级版 -->
  <!-- <test
    :firstName="firstName"
    @onFirstNameChanged="onFirstNameChanged($event)"
  /> -->

  <!-- 终极版 -->
  <test v-model:firstName="firstName" v-model:lastName="lastName" />

  <!-- 使用hooks -->
  <Dome2 v-if="isShow" />
  <button @click="changeIsShow">change isshow</button>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import Dome2 from "@/components/Dome/Dome2.vue";
// 导入ref
import { ref } from "vue";
import test from "@/components/day03/test.vue";
export default defineComponent({
  name: "App",
  // 组合式API入口

  setup() {
    // 定义参数
    const firstName = ref("halon");
    const lastName = ref("张三");
    const onClickHandler = () => {
      firstName.value = "freelaeder";
    };
    const onFirstName = (data: any) => {
      console.log("ee", data);
    };

    // 控制 Dome2 显示隐藏
    const isShow = ref(true);

    const changeIsShow = () => {
      isShow.value = !isShow.value;
    };

    // 升级版额
    const onFirstNameChanged = (event: any) => {
      firstName.value = event;
    };
    // 返回值
    return {
      firstName,
      lastName,
      onClickHandler,
      onFirstName,
      onFirstNameChanged,
      isShow,
      changeIsShow,
    };
  },
  components: { test, Dome2 },
});
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
